import React, { Component } from 'react';
import { createPortal } from 'react-dom';
import ReactEcharts from 'echarts-for-react';
import darkEchartsTheme from '../../config/theme/darkEchartsTheme';
import echarts from 'echarts';

const modalRoot = document.getElementById('dialog-root');

class IndustrymapDevelopNumTopChart extends Component {
  constructor(props) {
    super(props);
    this.el = document.createElement('technologyCollegeNumChart');
    this.state = {
      chartOption: undefined,
      chartHeight: 250,
    };
  }
  componentDidMount() {
    modalRoot.appendChild(this.el);
    // echarts.registerTheme('theme_name', darkEchartsTheme);
    this.setChartData();
  }
  setChartData() {
    const option = {
      title: {
        text: "26.4%",
        subtext: '国家开发区\n全国占比',
        x: 'center',
        y: 'center',
        textStyle: {
          color: "#fff",
          fontSize: 30,
          fontWeight: 'normal'
        },
        subtextStyle: {
          color: "#fff",
          fontSize: 14,
          fontWeight: 'normal'
        }
      },
      tooltip: {
        show: false,
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
      },
      calculable: true,
      series: [
        {
          name: '',
          type: 'pie',
          radius: [75, 90],
          center: ['50%', '50%'],
          data: [{
            value: 65,
            name: '国家开发区数量',
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                offset: 0,
                color: '#f6e3a1'
              }, {
                offset: 1,
                color: '#ff4236'
              }])
            },
            label: {
              color: "#fff",
              fontSize: 14,
              formatter: '长三角\n{a|65}个',
              rich: {
                a: {
                  color: "#fff",
                  fontSize: 20,
                  lineHeight: 30
                },
              }
            }
          },
          {
            value: 154,
            name: 'rose2',
            itemStyle: {
              color: "transparent",
              labelLine: {
                show: false
              },
            }
          }
          ]
        },
        {
          name: '',
          type: 'pie',
          radius: [80, 85],
          center: ['50%', '50%'],
          itemStyle: {
            normal: {
              label: {
                show: false
              },
              labelLine: {
                show: false
              }
            }
          },
          data: [{
            value: 65,
            name: '',
            itemStyle: {
              color: "transparent"
            }
          },
          {
            value: 154,
            name: 'rose2',
            itemStyle: {

              color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                offset: 0,
                color: '#348fe6'
              }, {
                offset: 1,
                color: '#625bef'
              }]),
              labelLine: {
                show: false
              },
            },
            label: {
              show: false,
            }
          }
          ]
        }
      ]
    };
    this.setState({ chartOption: option });
  }

  render() {
    const { style, width, height } = this.props;
    const dtTitle = `国家开发区数量全国占比`;
    const { chartOption } = this.state;
    return createPortal(
      <div
        style={{
          ...style,
          display: 'flex',
          flexDirection: 'column',
          width: width,
          height: height,
          color: '#fff',
          backgroundColor: 'rgba(0,0,0,0.6)',
          boxShadow: '0 1px 2px rgba(0,0,0,0.16), 0 1px 2px rgba(0,0,0,0.23)',
        }}
      >
        <div
          style={{
            lineHeight: '35px',
            height: 35,
            borderBottom: '1px solid rgb(238, 238, 238,0.2)',
            textAlign: 'center',
            fontWeight: 'bold'
          }}
        >
          <div style={{ float: 'left', marginLeft: 6, fontSize: 15 }}><div style={{ float: 'left', width: 5, height: 35, marginRight: 10, backgroundColor: 'rgba(63,177,277,1)', }} />{dtTitle}</div>
          <div style={{ float: 'right', marginRight: 8 }}>
          </div>
        </div>
        <div style={{ margin: '3px 8px 3px 8px' }}>
          <div>
            {chartOption !== undefined && (
              <ReactEcharts
                option={chartOption}
                notMerge={true}
                lazyUpdate={true}
                // theme={'theme_name'}
                style={{ height: this.state.chartHeight }}
              />
            )}
          </div>
        </div>
      </div>,
      this.el
    );
  }
}

export default IndustrymapDevelopNumTopChart;
